import { ref, onMounted } from 'vue';

export const usePrivacy = () => {
  const isAgree = ref(false);
  const privacyContractName = ref('《隐私保护指引》');

  const openContract = () => {
    if (wx.openPrivacyContract) {
      wx.openPrivacyContract();
    }
  };

  type TPrivacyRes = {
    errMsg: string;
    needAuthorization: boolean;
    privacyContractName: string;
  };

  const getPrivacySetting = () => {
    if (wx.getPrivacySetting) {
      wx.getPrivacySetting({
        success(res: TPrivacyRes) {
          console.log('打印***res', res);
          // privacyContractName.value = res.privacyContractName;
        }
      });
    }
  };

  onMounted(() => {
    getPrivacySetting();
  });

  return {
    isAgree,
    privacyContractName,
    openContract
  };
};
